package com.ruoyi.web.controller.production.seed;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.production.domain.seed.SeedAmount;
import com.ruoyi.production.service.seed.ISeedAmountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 种子量Controller
 *
 * @author ruoyi
 * @date 2021-07-08
 */
@RestController
@RequestMapping("/seed/amount")
public class SeedAmountController extends BaseController
{
    @Autowired
    private ISeedAmountService seedAmountService;

    /**
     * 查询种子量列表
     */
    @PreAuthorize("@ss.hasPermi('seed:amount:list')")
    @GetMapping("/list")
    public TableDataInfo list(SeedAmount seedAmount)
    {
        startPage();
        List<SeedAmount> list = seedAmountService.selectSeedAmountList(seedAmount);
        return getDataTable(list);
    }

    /**
     * 导出种子量列表
     */
    @PreAuthorize("@ss.hasPermi('seed:amount:export')")
    @Log(title = "种子量", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SeedAmount seedAmount)
    {
        List<SeedAmount> list = seedAmountService.selectSeedAmountList(seedAmount);
        ExcelUtil<SeedAmount> util = new ExcelUtil<SeedAmount>(SeedAmount.class);
        return util.exportExcel(list, "种子量数据");
    }

    /**
     * 获取种子量详细信息
     */
    @PreAuthorize("@ss.hasPermi('seed:amount:query')")
    @GetMapping(value = "/{seedAmountId}")
    public AjaxResult getInfo(@PathVariable("seedAmountId") Long seedAmountId)
    {
        return AjaxResult.success(seedAmountService.selectSeedAmountById(seedAmountId));
    }

    /**
     * 新增种子量
     */
    @PreAuthorize("@ss.hasPermi('seed:amount:add')")
    @Log(title = "种子量", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody SeedAmount seedAmount)
    {
        return toAjax(seedAmountService.insertSeedAmount(seedAmount));
    }

    /**
     * 修改种子量
     */
    @PreAuthorize("@ss.hasPermi('seed:amount:edit')")
    @Log(title = "种子量", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody SeedAmount seedAmount)
    {
        return toAjax(seedAmountService.updateSeedAmount(seedAmount));
    }

    /**
     * 删除种子量
     */
    @PreAuthorize("@ss.hasPermi('seed:amount:remove')")
    @Log(title = "种子量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{seedAmountIds}")
    public AjaxResult remove(@PathVariable Long[] seedAmountIds)
    {
        return toAjax(seedAmountService.deleteSeedAmountByIds(seedAmountIds));
    }
}
